url = 'https://www.acwing.com/problem/content/4945/'
n,m = map(int,input().split())

def check(n, m):  
    while m:  
        r = m % n  
        if r != 0 and r != 1 and r != n - 1:  
            return False  
        if r > 1:  
            r = -1  
        m = (m - r) / n  
    return True  

if check(n, m):  
    print("YES")  
else:  
    print("NO")